#!/bin/bash -e

# Prevents pushing any code to the server that does not comply with klint or detekt
# It ignores any unchecked files.

# Ignore any unchecked file
echo "Stashing changes before doing checks"
git stash push -q -u --keep-index

# Pop the stash once the scripts finishes, fails or gets cancelled
function pop_stash() {
    echo "Checks completed, popping stash"
    git stash pop -q
}

trap "exit" INT TERM ERR
trap pop_stash EXIT

# Do the actual check ups
./gradlew ktlintCheck detekt
